{include file="admin@public/header"/}

<style>
	#matchCon {
		width: 160px;
	}

	.url-box {
		padding: 5px 10px;
		line-height: 26px;
		cursor: pointer;
	}

	.url-box a {
		margin-right: 5px;
	}
	.mod-choose-input{position: relative;}
</style>


<div class="bill-ser-top">
	<ul class="ul-inline cf">
		<li>
			<input type="text" id="keyword" class="ui-input ui-input-ph" placeholder="请输入单据号或客户名或备注"
				style="width: 190px;">
		</li>
		<li>
			<label>日期:</label>
			<input type="date" id="startdate" class="ui-input " value="" style="width: 125px;">
			<i>-</i>
			<input type="date" id="enddate" class="ui-input " value="" style="width: 125px;">
		</li>

		<!-- 选择销售人员 -->
		{include file="admin@select/staff"/}

		<li>
			<div class="ui-btn-menu fl" id="filter-menu"> <span class="ui-btn menu-btn"> <span id="selected-date">收款状态:</span><b></b> </span>
			  <div class="con">
				<ul class="filter-list">
				<li>
					<input type="checkbox" name="hxState" value="未收款" class="vm" id="hxState_0"><label for="hxState_0">未收款</label>
					<input type="checkbox" name="hxState" value="部分收款" class="vm" id="hxState_1"><label for="hxState_1">部分收款</label>
					<input type="checkbox" name="hxState" value="全部收款" class="vm" id="hxState_2"><label for="hxState_2">全部收款</label>
				 </li>
				</ul>
			  </div>
			</div>
		</li>

		<li id="liConfirm">
			<div class="ui-btn-menu fl" id="filter-menu"> <span class="ui-btn menu-btn"> <span id="selected-confirm">对单状态:</span><b></b> </span>
			  <div class="con">
				<ul class="filter-list">
				<li>
					<input type="checkbox" name="cfState" value="0" class="vm" id="cfState_0"><label for="cfState_0">未核对</label>
					<input type="checkbox" name="cfState" value="1" class="vm" id="cfState_1"><label for="cfState_1">已核对</label>
				 </li>
				</ul>
			  </div>
			</div>
		</li>

		<li id="li_check">
			<label>审核状态:</label>
			<span id="span_checked">
				<span class="ui-combo-wrap" style="width: 118px;">
					<input type="text" class="input-txt" autocomplete="off" readonly="readonly" id="state_type_name" value="空" style="cursor: default; width: 92px;">
					<span class="trigger" id="state_type_trigger"></span>
				</span>
			</span>
		</li>

		<li><a class="mrb more ui-btn" id="moreCon" onclick="heightSearch('/admin/basic/hight_search.html?o_type={$o_type}','高级搜索','815px','460px')">高级搜索</a><a class="ui-btn mrb ui-btn-search" id="search">查询</a></li>
		<!-- <li class="url-box" id="openUrl"><a href="https://club.kingdee.com/club/newclub/school/course?product_id=7&amp;cid=1548#pid=5704" target="_blank" class="video-icon"></a>购货订单查询</li> -->
	</ul>
</div>

<!-- 审核状态 -->
{include file="admin@public/order/shenhe_state"/}

<div class="wrapper btc">
	<div class="bill-ser-botm cf">
		<div class="ui-config-box">
			<span id="config" class="ui-config"><a href="#" class="ui-icon-config-new"></a>列设置</span>
		</div>
		<div class="fr">
			<a class="ui-btn-bill ui-btn-add" id="add" onclick="addPage('/sales/invso/add.html','sales','销货单')">新增</a>
			<div class="ui-btn-menu ml10">
				<a class="ui-btn-bill ui-btn-hl menu-btn mrb" style="width: 40px;padding-right: 14px;" href="#"
					id="shenhe">审核<b></b></a>
				<div class="con hl more-operate-con" style="margin-left: 0px;font-size: 14px;width: 55px;padding: 6px;">
					<ul class="more-operate cf" style="border-style:dashed; border-width:1px; border-color:#ccc;">
						<li><a href="#" id="reshenhe" onclick="reAudit();">反审核</a></li>
					</ul>
				</div>
			</div>
			<div class="ui-btn-menu ml10">
				<a class="ui-btn-bill ui-btn-hl menu-btn mrb" href="#" id="print" target="_blank"
					href="javascript:void(0);">打印<b></b></a>
				<div class="con hl more-operate-con" style="margin-left: 0px;font-size: 14px;width: 54px;padding: 3px;">
					<ul class="more-operate cf" style="border-style:dashed; border-width:1px; border-color:#ccc;">
						<li style="padding-left: 8px;"><a href="#" id="printSet" href="javascript:void(0);">设置</a></li>
					</ul>
				</div>
			</div>
			<div class="ui-btn-menu ml10">
				<a class="ui-btn-bill ui-btn-hl menu-btn mrb" style="width: 40px;padding-right: 7px;" href="#"
					id="import" target="_blank" href="javascript:void(0);">导入<b></b></a>
				<div class="con hl more-operate-con" style="margin-left: 0px;font-size: 14px;width: 54px;padding: 3px;">
					<ul class="more-operate cf" style="border-style:dashed; border-width:1px; border-color:#ccc;">
						<li style="padding-left: 8px;"><a id="export">导出</a></li>
					</ul>
				</div>
			</div>
			<a href="#" class="ui-btn-bill ui-btn-hl ml10" id="del">删除</a>
			<div class="ui-btn-menu ml10" id="confirmBtns">
				<a class="ui-btn-bill ui-btn-hl menu-btn mrb" style="width: 50px;padding-right: 7px;padding-left: 23px;" href="#" id="confirmOrder">对单<b></b></a>
				<div class="con hl more-operate-con" style="margin-left: 0px;font-size: 14px;width: 74px;padding: 3px;">
				  <ul class="more-operate cf" style="border-style:dashed; border-width:1px; border-color:#ccc;">
					<li style="padding-left: 8px;"><a href="#" id="confirmCancel">撤销对单</a></li>
				  </ul>
				</div>
			</div>
		</div>
	</div>
	<div class="grid-wrap">
		<table id="grid">
		</table>
		<div id="page"></div>
	</div>
</div>


<script type="text/javascript">
	//$(function(){
	$(document).ready(function () {
		// 获取当前日期
		var myDate = new Date;
		var year = myDate.getFullYear(); //获取当前年
		var mon = myDate.getMonth() + 1; //获取当前月
		var date = myDate.getDate(); //获取当前日
		// console.log(year + '-' + mon + '-' + date)
		if (mon < 10) {
			mon = "0" + mon;
		}
		if (date < 10) {
			date = "0" + date;
		}
		$("#startdate").val(year + '-' + mon + '-01');
		$("#enddate").val(year + '-' + mon + '-' + date);


		// 鼠标移入订单状态
		$("#filter-menu").hover(function () {
			$(this).addClass("ui-btn-menu-cur");
		}, function () {
			$(this).removeClass("ui-btn-menu-cur");
		})
		// 按钮移入移出
		$(".ui-btn-menu.ml10").hover(function () {
			$(this).addClass("ui-btn-menu-cur");
		}, function () {
			$(this).removeClass("ui-btn-menu-cur");
		})

		//alert("1111");
		$("#grid").jqGrid({
			url: '/sales/invsa/index.html?ajax=100',
			datatype: "json",//数据来源，本地数据（local，json,jsonp,xml等）
			height: '90%',//高度，表格高度。可为数值、百分比或'auto'
			colNames: ["操作", "ID","单据日期", "单据编号","销售人员", "源销货订单号","客户类别","客户",  "数量","销售金额", "优惠后金额","已收款", "收款状态","对单状态", "制单人", "审核人","最后修改人","最后修改时间", "备注", "打印次数", '快递单号','订单状态','type'],
			colModel: [
				{ name: 'actions', width: 80, formatter: actions,align:'center' },
				{ name: 'id',hidden:true },
				{ name: 'dj_time',width: 90,align:'center'},
				{ name: 'sn',width: 120,align:'center' },
				{ name: 'by_admin_name', width: 80,align:'center'},
				{ name: 'xhdd_sn',width: 150,align:'center',formatter: xhdd_sn_formatter },
				{ name: 'customer_cate_name',width: 150,align:'center' },//客户类别
				{ name: 'customer_name',width: 150,align:'center' },
				{ name: 'shuliang' ,width: 90,align:'center'},
				{ name: 'before_yh_price',width: 90,align:'center' },
				{ name: 'yh_price',width: 90,align:'center' },
				{ name: 'payment' ,width: 90,align:'center'},
				{ name: 'pay_status_name',width: 90,align:'center' },//收款状态
				{ name: 'dd_status_name',width: 90,align:'center' },//对单状态
				{ name: 'add_user_name',width: 90,align:'center' },
				{ name: 'shenhe_user_name',width: 90,align:'center' },
				{ name: 'last_user_name',width: 90,align:'center' },//最后修改人
				{ name: 'updatetime',width: 90,align:'center' },//最后修改时间
				{ name: 'mark',width: 150,align:'center' },
				{ name: 'print_number' ,width: 90,align:'center'},
				{ name: 'export',width: 150,align:'center' },
				{ name: 'status',hidden:true },
				{ name: 'type', hidden: true },
			],
			sortable: true,  //排序
		
			rowNum: 10,
			rowList: [10, 20, 30],
			sortname: 'id',
			sortorder: "desc",
			pagerpos: "left",//分页位置
			multiselect:true,
			pgbuttons: true,//翻页按钮
			pagination: true,
			altRows: !0,
			gridview: !0,
			shrinkToFit: !1,
			cellLayout: 8,
			autowidth: !0,
			pager: "#page",
			viewrecords: !0,
			cmTemplate: {
				sortable: !1,
				title: !1
			},
			loadError: function (t, e, i) {
				parent.Public.tips({
					type: 1,
					content: "操作失败了哦，请检查您的网络链接！"
				})
			},
			// 合计
			footerrow: true,
			gridComplete: function () {
				var before_yh_price = parseFloat($("#grid").getCol('before_yh_price', false, 'sum')).toFixed(2);//销售金额
				var shuliang = parseFloat($("#grid").getCol('shuliang', false, 'sum')).toFixed(2);//销售数量
				$("#grid").footerData('set', { "customer_name": '合计', "before_yh_price": before_yh_price ,"shuliang":shuliang });
				var grid = $("#grid");
				var col_hs = grid.getCol('col_h', false);//获取某一列
				var ids = grid.getDataIDs();
				var rowDatas = grid.jqGrid("getRowData");//获取所有行的数据
				//alert(col_hs);
				for (var i = 0; i < ids.length; i++) {
					//设置行高
					grid.setRowData(ids[i], false, { height: 40 * col_hs[i] });
					var rowData = rowDatas[i];
					if (rowData.status == "0") {
						$("#" + ids[i] + " td").css("color", "#999999");
					}
				}
			},
			//双击表格行事件
            ondblClickRow: function(row){
                var rowData = $('#grid').jqGrid('getRowData',row);
                console.log(rowData.id);
                //var start_date = $('input[name=start_date]').val();
                //var end_date = $('input[name=end_date]').val();
                parent.tab.addTabItem({
                    tabid: "purchaseinvSa",
                    text: "销货单",
                    url:"/sales/invsa/edit.html?id="+rowData.id,
                })
                   
            }
		});
	});


	//工具栏
	function actions(cellvalue, options, rowObject) {
		return '<div class="operating"><span class="ui-icon ui-icon-pencil" onclick="edit(' + rowObject.id + ')">修改</span> <span class="ui-icon ui-icon-trash" onclick="order_del(' + rowObject.id + ')">删除</span></div>';
	}

	function xhdd_sn_formatter(cellvalue, options, rowObject) {
		if (rowObject.xhdd_sn==null) {
			rowObject.xhdd_sn='';
		}
		return '<a onclick="addPage('+'\'/sales/invso/edit.html?id='+rowObject.xhdd_id+'\',\'salesOrder\',\'销货订单\')">'+ rowObject.xhdd_sn +'</a>';
	}

	function edit(id) {
		parent.tab.addTabItem({
			tabid: "purchaseinvSa",
			text: "销货单",
			url: "/sales/invsa/edit.html?id=" + id,
		})
	}	

</script>


<script type="text/javascript">
	//$action_type 0 查询 1 导出
	function grid_search_list($action_type){
		var startdate = $('#startdate').val();
		var enddate = $('#enddate').val();
		var keyword = $('#keyword').val();//关键字

		var hxState=document.getElementsByName('hxState'); 
		//获取付款状态
		var str=''; 
		for(var i=0; i<hxState.length; i++){ 
			if(hxState[i].checked) str+=hxState[i].value+','; //如果选中，将value添加到变量s中 
		} 
		var pay_status_name=str.slice(0, -1);//订单状态

		//获取对单状态
		var obj=document.getElementsByName('cfState'); 
		var str=''; 
		for(var i=0; i<obj.length; i++){ 
			if(obj[i].checked) str+=obj[i].value+','; //如果选中，将value添加到变量s中 
		} 
		var dd_status=str.slice(0, -1);//订单状态

		var state_id=$("#state_type_id").val();//审核状态

		// alert(state_id);
		var by_admin=$("#staff_id").val();//销售人员

	
		$("div.grid-subtitle").text("日期: " + startdate + " 至 " + enddate);


		if ($action_type==0) {
			var param={ 'ajax': '100', 'startdate': startdate, 'enddate': enddate, 'keyword': keyword,'state_id':state_id,'pay_status_name':pay_status_name,dd_status:dd_status,by_admin:by_admin};  //发送数据
		}else if($action_type==1){
			var param={ 'is_export':1,'ajax': '100', 'startdate': startdate, 'enddate': enddate, 'keyword': keyword,'state_id':state_id,'pay_status_name':pay_status_name,dd_status:dd_status,by_admin:by_admin};
			var export_param='';
			for(let key  in param){
				export_param+=key+'='+ param[key]+'&';
			}
			export_param = export_param.substr(0, export_param.length - 1);  
			//console.log(export_param);
			window.location.href="index.html?"+export_param;
			return false;
		}
	
		

		//此处可以添加对查询数据的合法验证 
		$("#grid").jqGrid('setGridParam', {
			datatype: 'json',
			postData: param, //发送数据 
			page: 1
		}).trigger("reloadGrid"); //重新载入 

	}


	$(document).ready(function () {
		// 导出按钮
		$("#export").click(function () {
			grid_search_list(1);//0 查询 1 导出
		});

		// 点击查询按钮
		$("#search").click(function () {
			grid_search_list(0);//0 查询 1 导出
		});
	});

		
</script>
<script type="text/javascript">
  $(document).ready(function () {
    // 审核按钮
    $("#shenhe").click(function () {
    	//alert("1111111");
      	var ids = $("#grid").jqGrid('getGridParam','selarrrow');

		if (ids == '' || ids == null) {
			layer.msg('请先选择需要审核的项！');
			return false;
		}
		//获取商品信息
		$.post('shenhe.html', { ids: ids, status: 1,type:1}, function (res) {
			layer.msg(res.msg);
			if (res.status == 1) {
				reload();
			}
		});
    })

    // 反审核按钮
    $("#reshenhe").click(function () {
    	var ids = $("#grid").jqGrid('getGridParam','selarrrow');
      	if (ids == '' || ids == null) {
			layer.msg('请先选择需要反审核的项！');
			return false;
		}
		//获取商品信息
		$.post('shenhe.html', { ids: ids, status: 0,type:2 }, function (res) {
			layer.msg(res.msg);
			if (res.status == 1) {
				reload();
			}
		});
    })
    // 对单
    $("#dd").click(function () {
      	var ids = $("#grid").jqGrid('getGridParam','selarrrow');

		if (ids == '' || ids == null) {
			layer.msg('请先选择需要操作的项！');
			return false;
		}
		//获取商品信息
		$.post('dd.html', { ids: ids,type:1 }, function (res) {
			layer.msg(res.msg);
			if (res.status == 1) {
				reload();
			}
		});
    })

    // 撤销对单
    $("#redd").click(function () {
    	var ids = $("#grid").jqGrid('getGridParam','selarrrow');
      	if (ids == '' || ids == null) {
			layer.msg('请先选择需要操作的项！');
			return false;
		}
		//获取商品信息
		$.post('dd.html', { ids: ids,type:2 }, function (res) {
			layer.msg(res.msg);
			if (res.status == 1) {
				reload();
			}
		});
    })

    // 删除订单
    $("#del").click(function () {
    	//alert("111");
    	var ids = $("#grid").jqGrid('getGridParam','selarrrow');
      	if (ids == '' || ids == null) {
			layer.msg('请先选择需要删除的项！');
			return false;
		}
		//获取商品信息
		$.post('del.html', { ids: ids}, function (res) {
			layer.msg(res.msg);
			if (res.status == 1) {
				reload();
			}
		});
    })

    
});
</script>

{include file="admin@public/footer"/}